<template>
  <yl-crud ref="crud" :add="add" :table="table" :update="update" :view="view" />
</template>
<script>
import YlCrud from '../../components/CRUD/index'

export default {
  name: 'AppVersion',
  components: { YlCrud },
  data() {
    return {
      table: {
        url: '/api/portal/appVersion/queryList',
        params: {},
        columns: [
          {
            type: 'index'
          },
          {
            prop: 'versionName',
            label: '版本名称'
          },
          {
            prop: 'versionCode',
            label: '版本编号'
          },
          {
            prop: 'downloadUrl',
            label: '下载地址'
          },
          {
            prop: 'isForcedUpdate',
            label: '是否强制更新',
            render: (h, row) => {
              let text = ''
              if (row.isForcedUpdate === '0') {
                text = '否'
              }
              if (row.isForcedUpdate === '1') {
                text = '是'
              }
              return h('div', text)
            }
          },
          {
            prop: 'terminalType',
            label: '终端类型',
            render: (h, row) => {
              let text = ''
              if (row.terminalType === '0') {
                text = 'ios'
              }
              if (row.terminalType === '1') {
                text = 'android'
              }
              return h('div', text)
            }
          },
          {
            width: 150,
            type: 'handle',
            handle: ['view', 'update']
          }
        ]
      },
      add: {
        title: '添加',
        url: '/api/portal/appVersion/save',
        columns: [
          {
            label: '版本名称',
            type: 'text',
            prop: 'versionName',
            rules: [
              { required: true, message: '请输入版本名称', trigger: 'change' },
              { max: 50, message: '最大不超过50个字', trigger: 'blur' }
            ]
          },
          {
            label: '版本号',
            type: 'text',
            prop: 'versionCode',
            rules: [
              { required: true, message: '请输入版本号', trigger: 'change' },
              { max: 50, message: '最大不超过50个字', trigger: 'blur' }
            ]
          },
          {
            label: '下载地址',
            type: 'url',
            prop: 'downloadUrl',
            rules: [
              { required: true, message: '请输入版本号', trigger: 'change' },
              { type: 'url', message: '格式错误', trigger: 'blur' }
            ]
          },
          {
            label: '强制更新',
            type: 'radio',
            prop: 'isForcedUpdate',
            value: 0,
            options: [
              { key: 1, label: '是' },
              { key: 0, label: '否' }
            ],
            rules: [{ required: true, message: '请选择是否强制更新', trigger: 'change' }]
          },
          {
            label: '终端类型',
            type: 'radio',
            prop: 'terminalType',
            options: [
              { key: 1, label: 'android' },
              { key: 0, label: 'ios' }
            ],
            rules: [{ required: true, message: '请选择终端类型', trigger: 'change' }]
          },
          {
            label: '更新内容',
            type: 'textarea',
            prop: 'content',
            rules: [
              { required: true, message: '请输入更新内容', trigger: 'change' },
              { max: 50, message: '最大不超过500个字', trigger: 'blur' }
            ]
          }
        ]
      },
      update: {
        title: '编辑',
        getUrl: '/api/portal/appVersion/queryDetail',
        postUrl: '/api/portal/appVersion/save',
        columns: [
          {
            label: '版本名称',
            type: 'text',
            prop: 'versionName',
            rules: [
              { required: true, message: '请输入版本名称', trigger: 'change' },
              { max: 50, message: '最大不超过50个字', trigger: 'blur' }
            ]
          },
          {
            label: '版本号',
            type: 'text',
            prop: 'versionCode',
            rules: [
              { required: true, message: '请输入版本号', trigger: 'change' },
              { max: 50, message: '最大不超过50个字', trigger: 'blur' }
            ]
          },
          {
            label: '下载地址',
            type: 'url',
            prop: 'downloadUrl',
            rules: [
              { required: true, message: '请输入版本号', trigger: 'change' },
              { type: 'url', message: '格式错误', trigger: 'blur' }
            ]
          },
          {
            label: '强制更新',
            type: 'radio',
            prop: 'isForcedUpdate',
            value: '0',
            options: [
              { key: '1', label: '是' },
              { key: '0', label: '否' }
            ],
            rules: [{ required: true, message: '请选择是否强制更新', trigger: 'change' }]
          },
          {
            label: '终端类型',
            type: 'radio',
            prop: 'terminalType',
            options: [
              { key: '1', label: 'android' },
              { key: '0', label: 'ios' }
            ],
            rules: [{ required: true, message: '请选择终端类型', trigger: 'change' }]
          },
          {
            label: '更新内容',
            type: 'textarea',
            prop: 'content',
            rules: [
              { required: true, message: '请输入更新内容', trigger: 'change' },
              { max: 50, message: '最大不超过500个字', trigger: 'blur' }
            ]
          }
        ]
      },
      view: {
        title: '查看',
        url: '/api/portal/appVersion/queryDetail',
        columns: [
          {
            prop: 'versionName',
            label: '版本名称'
          },
          {
            prop: 'versionCode',
            label: '版本编号'
          },
          {
            prop: 'downloadUrl',
            label: '下载地址'
          },
          {
            prop: 'isForcedUpdate',
            label: '是否强制更新',
            render: (h, row) => {
              let text = ''
              if (row.isForcedUpdate === '0') {
                text = '否'
              }
              if (row.isForcedUpdate === '1') {
                text = '是'
              }
              return h('div', text)
            }
          },
          {
            prop: 'terminalType',
            label: '终端类型',
            render: (h, row) => {
              let text = ''
              if (row.terminalType === '0') {
                text = 'ios'
              }
              if (row.terminalType === '1') {
                text = 'android'
              }
              return h('div', text)
            }
          },
          {
            label: '更新内容',
            prop: 'content'
          }
        ]
      }
    }
  }
}
</script>

<style scoped>
</style>
